package com.vinci.task.service.impl;

import com.vinci.task.entity.TbTaskInfo;
import com.vinci.task.entity.TbTaskSelfRecommendationRegistration;
import com.vinci.task.mapper.TbTaskSelfRecommendationRegistrationMapper;
import com.vinci.task.service.TbTaskSelfRecommendationRegistrationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 自荐报名表 服务实现类
 * </p>
 *
 * @author 张先生
 * @since 2021-12-11
 */
@Service
public class TbTaskSelfRecommendationRegistrationServiceImpl extends ServiceImpl<TbTaskSelfRecommendationRegistrationMapper, TbTaskSelfRecommendationRegistration> implements TbTaskSelfRecommendationRegistrationService {

    @Autowired(required = false)
    private TbTaskSelfRecommendationRegistrationMapper tbRegistrationMapper;

    /**
     * 查询自荐人员
     * @param tbRegistration
     * @return
     */

    @Override
    public List<TbTaskSelfRecommendationRegistration> selectRegistration(TbTaskSelfRecommendationRegistration tbRegistration) {
        List<TbTaskSelfRecommendationRegistration> tbTaskSelfRecommendationRegistrations = null;

        try {
            tbTaskSelfRecommendationRegistrations = tbRegistrationMapper.selectRegistration(tbRegistration);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return tbTaskSelfRecommendationRegistrations;
    }

    /**
     * 添加自荐人员
     * @param tbRegistration
     */
    @Override
    public void insertRegistration(TbTaskSelfRecommendationRegistration tbRegistration) {

        try {
            String uuid = UUID.randomUUID().toString().replace("-", "");
            tbRegistration.setSelfId(uuid);
            tbRegistration.setDelflag(0);
            tbRegistration.setCreateTime(new Timestamp(System.currentTimeMillis()));
            tbRegistration.setUpdateTime(new Timestamp(System.currentTimeMillis()));

            tbRegistrationMapper.insertRegistration(tbRegistration);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 根据id查询对应任务
     * @param taskId
     * @return
     */
    @Override
    public TbTaskInfo selectTaskInfo(String taskId) {

        TbTaskInfo tbTaskInfo = null;
        try {
            tbTaskInfo = tbRegistrationMapper.selectTaskInfo(taskId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return tbTaskInfo;
    }
}
